package com.campus.counseling.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.campus.counseling.entity.ConsultationRecord;
import com.campus.counseling.model.common.Result;
import com.campus.counseling.model.dto.RecordRateDTO;
import com.campus.counseling.service.ConsultationRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/record")
@RequiredArgsConstructor
public class ConsultationRecordController {

    private final ConsultationRecordService consultationRecordService;

    @GetMapping("/list")
    public Result<IPage<ConsultationRecord>> getRecordList(
            @RequestParam(defaultValue = "1") Long page,
            @RequestParam(defaultValue = "10") Long size,
            ConsultationRecord query) {
        return Result.success(consultationRecordService.getRecordList(page, size, query));
    }

    @PostMapping("/create")
    public Result<Void> addRecord(@RequestBody ConsultationRecord record) {
        consultationRecordService.addRecord(record);
        return Result.success();
    }

    @PutMapping("/update")
    public Result<Void> updateRecord(@RequestBody ConsultationRecord record) {
        consultationRecordService.updateRecord(record);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result<Void> deleteRecord(@PathVariable Long id) {
        consultationRecordService.deleteRecord(id);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result<ConsultationRecord> getRecordDetail(@PathVariable Long id) {
        return Result.success(consultationRecordService.getRecordDetail(id));
    }

    @GetMapping("/appointment/{appointmentId}")
    public Result<ConsultationRecord> getRecordByAppointmentId(@PathVariable Long appointmentId) {
        return Result.success(consultationRecordService.getRecordByAppointmentId(appointmentId));
    }

    @PostMapping("/rate")
    public Result rate(@RequestBody RecordRateDTO rateDTO) {
        consultationRecordService.rateRecord(rateDTO);
        return Result.success();
    }
}